//Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using NUnit.Framework;

namespace Microsoft.Office.OneNote.UnitTests
{
	/// <summary>
	/// Tests the SectionGroup class.
	/// </summary>
	[TestFixture]
	public class SectionGroupTest
	{
		[SetUp]
		public void Init()
		{
			NotebookRoot root = OneNote.Application.NotebookRoot;

			// Let's create a new notebook:
			Notebook testNotebook = TestUtils.CreateEmptyNotebook();

			using (HierarchyTransaction addGroup = new HierarchyTransaction(testNotebook))
			{
				this.testGroup = new SectionGroup("test group");
				testNotebook.AppendChild(testGroup);
			}
		}

		[TearDown]
		public void Dispose()
		{
			TestUtils.CloseAndDeleteNotebook((Notebook) this.testGroup.Parent);
			this.testGroup = null;
		}

		[Test]
		public void Construction()
		{
		}

		[Test]
		public void AddSectionGroup()
		{
			Assert.IsTrue(this.testGroup.GetChildCount() == 0);

			using (HierarchyTransaction createSectionGroup = new HierarchyTransaction(testGroup))
			{
				this.testGroup.AppendChild(new SectionGroup("Test Group"));
			}

			Assert.IsTrue(this.testGroup.GetChildCount() == 1);
		}

		[Test]
		public void DeleteSectionGroup()
		{
			Assert.IsTrue(this.testGroup.GetChildCount() == 0);

			using (HierarchyTransaction createAndDeleteSectionGroup = new HierarchyTransaction(testGroup))
			{
				this.testGroup.AppendChild(new SectionGroup("Test Sub-Group"));
				createAndDeleteSectionGroup.Commit();

				Assert.IsTrue(this.testGroup.GetChildCount() == 1);

				this.testGroup.DeleteChild(this.testGroup.GetChild(0));
			}

			Assert.IsTrue(this.testGroup.GetChildCount() == 0);
		}

		[Test]
		public void AddSection()
		{
			Assert.IsTrue(this.testGroup.GetChildCount() == 0);

			using (HierarchyTransaction createSection = new HierarchyTransaction(testGroup))
			{
				this.testGroup.AppendChild(new Section("Test Section"));
			}

			Assert.IsTrue(this.testGroup.GetChildCount() == 1);
		}


		[Test]
		public void DeleteSection()
		{
			Assert.IsTrue(this.testGroup.GetChildCount() == 0);

			using (HierarchyTransaction createAndDeleteSection = new HierarchyTransaction(testGroup))
			{
				this.testGroup.AppendChild(new Section("Test Section"));
				createAndDeleteSection.Commit();
				Assert.IsTrue(this.testGroup.GetChildCount() == 1);

				this.testGroup.DeleteChild(this.testGroup.GetChild(0));
			}

			Assert.IsTrue(this.testGroup.GetChildCount() == 0);
		}

		private SectionGroup testGroup = null;
	}
}